from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class RegisterOption:

    def __init__(self, driver):
        self.driver = driver

    def register_option(self, username, password, re_password):
        re_password = re_password if re_password else ''
        password = password if password else ''
        self.driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(username)
        self.driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(password)
        self.driver.find_element(By.XPATH, '//*[@id="repassword"]').send_keys(re_password)
        self.driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()

    def get_username_tip(self):
        wait = WebDriverWait(self.driver, 3)
        element = wait.until(
            EC.presence_of_element_located((By.XPATH, '/html/body/div/div/div/form/div[1]/span[1]')))
        return element.text

    def get_password_tip(self):
        wait = WebDriverWait(self.driver, 3)
        element = wait.until(
            EC.presence_of_element_located((By.XPATH, '/html/body/div/div/div/form/div[2]/span[1]')))
        return element.text

    def get_re_password_tip(self):
        wait = WebDriverWait(self.driver, 3)
        element = wait.until(
            EC.presence_of_element_located((By.XPATH, '/html/body/div/div/div/form/div[3]/span[1]')))
        return element.text
